<template>
	<view class="login">
		<view class="login-title">用户登录</view>
		<view class="login-content">
			<view class="login-username">
				<uni-icons type="person-filled" size="30"></uni-icons>
				<input type="text" placeholder="请输入账号" v-model="phone">
			</view>
			<view class="login-password">
				<uni-icons type="locked" size="30"></uni-icons>
				<input type="password" placeholder="请输入密码" v-model="password">
			</view>
		</view>
		<view class="button"><button @click="onsubmit">登录</button></view>
		<view class="login-botton">
			<view class="login-password" @click="findPassword">找回密码</view>
			<span>|</span>
			<view class="login-zhuce" @click="Registration">注册账号</view>
		</view>
	</view>
</template>

<script>
	import {login} from "@/api/login.js"
	export default {
		data() {
			return {
				phone: '',
				password: '',
				rules: {
					phone: [{
						required: true,
						message: '请输入手机号',
						rule: '/^1[23456789]\d{9}$/'
					}],
					password: [{
						required: true,
						message: '请输入密码',
						trigger: 'blur'
					}]
				}
			};
		},
		methods: {
			//登录
			onsubmit() {
				if (this.phone == '' || this.password == '') {
					uni.showToast({
						title: "内容不能为空哦！",
						icon: "none"
					})
				} else {
					let data = {
						userName: this.phone,
						password: this.password
					}
					login(data).then(res =>{
						// 把用户信息存入缓存中
						if(res.code == 200){
							uni.setStorage({
								key: 'token',
								data: res.data.token
							});
							uni.setStorage({
								key: 'userVO',
								data: res.data.userVO
							});
							uni.switchTab({
								url:"/pages/me/index"
							})
						}
					});
	
				}
			},
			Registration() {
				console.log('hah ');
				uni.navigateTo({
					url: '../../pages/login/registration'
				});
			},
			findPassword() {
			}
		}
	};
</script>

<style lang="less">
	.login {
		background-color: #fff;
		width: 100%;
		background-position: center;
		background-size: cover;
		margin: 0px;
		background-size: 100% 100%;
		background-attachment: fixed;
		height: 1535rpx;
		opacity: 0.8;

		.login-title {
			padding-top: 150rpx;
			display: flex;
			justify-content: flex-start;
			margin-left: 50rpx;
			font-weight: 700;
			font-size: 40rpx;
			color: #ffd524;
			letter-spacing: 5rpx;
			margin-bottom: 50rpx;
		}

		.login-content {
			.login-username {
				display: flex;
				align-items: center;
				margin: 0 50rpx;
				border-bottom: 1rpx solid gainsboro;

				input {
					padding: 10rpx;
					height: 60rpx;
					width: 80%;
				}
			}

			.login-password {
				display: flex;
				align-items: center;
				margin: 0 50rpx;
				border-bottom: 1rpx solid gainsboro;
				margin-top: 50rpx;

				input {
					padding: 10rpx;
					height: 60rpx;
					width: 80%;
				}
			}
		}

		.button {
			margin-top: 120rpx;

			button {
				background-color: #ffd524;
				width: 90%;
				height: 85rpx;
				text-align: center;
				line-height: 85rpx;
				color: #fff;
			}
		}

		.login-botton {
			display: flex;
			justify-content: center;
			margin-top: 100rpx;

			.login-password {
				padding: 0 15rpx;
				color: #ffd524;
			}

			.login-zhuce {
				padding: 0 15rpx;
				color: #ffd524;
			}
		}
	}
</style>